package com.lzx.spring3.aop.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.lzx.spring3.dao.UserDao;
import com.lzx.spring3.dao.impl.UserDaoImpl;
import com.lzx.spring3.meta.User;
import com.lzx.spring3.meta.Watch;

public class Main {

	public static void main(String[] args) throws IllegalArgumentException,
			IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
		UserDao userDao = (UserDao) new UserDaoImpl();

		int times = 5000000;

		Watch.start();
		int count = times;
		while (count > 0) {
			count--;
			userDao.add(new User());
		}
		Watch.dis();

		Method[] methods = userDao.getClass().getMethods();
		Method method = null;
		for (Method m : methods) {
			if (m.getName().equals("add")) {
				method = m;
			}
		}

		Watch.start();
		count = times;
		while (count > 0) {
			count--;
//			method = userDao.getClass().getMethod("add", User.class);
			method.setAccessible(true);
			method.invoke(userDao, new User());
		}
		Watch.dis();

	}

}
